DynInc is a Java based dynamic invocation framework that provides an expression language based on EL. DynInc provides similar functionality like JEXL orJXPath.
So, why another expression language? Well, the basic idea behind DynInc is to provide as much of functionality as you need, but really nothing more. Or putting it in other words, we try to follow the YAGNI principle.
DynInc's main component is a Parser that parses (string) expressions into an object tree. This tree can then be "executed" with a context containing arbitrary Java objects. Depending on the expression, properties of the Java objects are get, methods are invoked and the final result object is returned. So in fact, DynInc is really nothing new :)
Let's look an example. we first fill the context with two simple objects: a map and a string.
// Create the context Context context = new DefaultContextImpl(); // Create a string and put it into the context String test = "Test"; context.put("ref", test); // Create a map and put it into the context Map map = new HashMap(); context.put("map", map); map.put("a", "Hallo"); map.put("b", "World");
Now, we can use a parser to parse an expression:
Expression exprA = parse.parse("ref"); Expression exprB = parse.parse("ref.length()"); Expression exprC = parse.parse("map.a");
The expressions are self explaining: the first one fetches the value of 'ref', the second one invokes the length() method on this string object and the third one fetches the object stored under the key 'a' out of the map.
You get the value of an expression by calling the getValue() method. An expression is ThreadSafe, so it can safely used in multi-threaded environments.
Object value = exprA.getValue( context );